#ifndef __TEST_PUB_DEBUG_H
#define __TEST_PUB_DEBUG_H
#include <stdio.h>


/**
 * 处理2个参数
 */
#define API_ENTRY_PARE2(nr, rets, pval1, pval2) \
asm volatile(\
         "mov x8, %[sysnr]\n\t"\
         "mov x0, %[prv1]\n\t"\
         "mov x1, %[prv2]\n\t"\
         "svc #0 \n\t"\
		 "mov %[retval], x0 \n\t"\
         :[retval] "=r" (rets)\
         :[sysnr] "r" (nr),[prv1]"r" (pval1),\
		 [prv2]"r" (pval2)\
         :"x8","x0","x1","cc","memory"\
    )

/**
 * 处理3个参数
 */
#define API_ENTRY_PARE3(nr, rets, pval1, pval2, pval3) \
asm volatile(\
         "mov x8, %[sysnr]\n\t"\
         "mov x0, %[prv1]\n\t"\
         "mov x1, %[prv2]\n\t"\
         "mov x2, %[prv3]\n\t"\
         "svc #0 \n\t"\
		 "mov %[retval], x0 \n\t"\
         :[retval] "=r" (rets)\
         :[sysnr] "r" (nr), \
         [prv1]"r" (pval1),\
		 [prv2]"r" (pval2),\
		 [prv3]"r" (pval3)\
         :"x8","x0","x1","x2","cc","memory"\
    )

long syscall_intface2(long nr, long pval1, long pval2)
{
	long ret;

	API_ENTRY_PARE2(nr, ret, pval1, pval2);

	return ret;
}

long syscall_intface3(long nr, long pval1, long pval2, long pval3)
{
	long ret;

	API_ENTRY_PARE3(nr, ret, pval1, pval2, pval3);

	return ret;
}

#define __NR_xby_printk 1203
#define __NR_example 0

static int debug_printf(const char *fmt, ...)
{
	int ret, len;
	char buf[1024];
	va_list ap;

	memset(buf, 0, 1024);
	va_start(ap, fmt);
	len = vsnprintf(buf, 1024, fmt, ap);
	buf[len] = 0;
	va_end(ap);
	ret = syscall_intface2(__NR_xby_printk, (long)buf, len);

	return 0;
}

static inline void msleep(int msec)
{
	struct timespec ts;

	ts.tv_sec = 0;
	ts.tv_nsec = msec * 1000 * 1000;
	nanosleep(&ts, NULL);
}

#endif /* __TEST_PUB_DEBUG_H */